home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstInsert.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  2.4 KB  |  113 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     89.06.13.15.01.43;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.6
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.40.
  23. @
  24. text
  25. @/*-
  26.  * LstInsert.c --
  27.  *    Insert a new datum before an old one
  28.  *
  29.  * Copyright (c) 1988 by University of California Regents
  30.  *
  31.  * Permission to use, copy, modify, and distribute this
  32.  * software and its documentation for any purpose and without
  33.  * fee is hereby granted, provided that the above copyright
  34.  * notice appears in all copies.  Neither the University of California nor
  35.  * Adam de Boor makes any representations about the suitability of this
  36.  * software for any purpose.  It is provided "as is" without
  37.  * express or implied warranty.
  38.  */
  39. #ifndef lint
  40. static char *rcsid =
  41. "$Id: lstInsert.c,v 1.6 89/06/13 15:01:43 adam Exp $ SPRITE (Berkeley)";
  42. #endif lint
  43.  
  44. #include    "lstInt.h"
  45.  
  46. /*-
  47.  *-----------------------------------------------------------------------
  48.  * Lst_Insert --
  49.  *    Insert a new node with the given piece of data before the given
  50.  *    node in the given list.
  51.  *
  52.  * Results:
  53.  *    SUCCESS or FAILURE.
  54.  *
  55.  * Side Effects:
  56.  *    the firstPtr field will be changed if ln is the first node in the
  57.  *    list.
  58.  *
  59.  *-----------------------------------------------------------------------
  60.  */
  61. ReturnStatus
  62. Lst_Insert (l, ln, d)
  63.     Lst                  l;    /* list to manipulate */
  64.     LstNode          ln;    /* node before which to insert d */
  65.     ClientData          d;    /* datum to be inserted */
  66. {
  67.     register ListNode    nLNode;    /* new lnode for d */
  68.     register ListNode    lNode = (ListNode)ln;
  69.     register List     list = (List)l;
  70.  
  71.  
  72.     /*
  73.      * check validity of arguments
  74.      */
  75.     if (LstValid (l) && (LstIsEmpty (l) && ln == NILLNODE))
  76.     goto ok;
  77.     
  78.     if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
  79.     return (FAILURE);
  80.     }
  81.     
  82.     ok:
  83.     PAlloc (nLNode, ListNode);
  84.     
  85.     nLNode->datum = d;
  86.     nLNode->useCount = nLNode->flags = 0;
  87.     
  88.     if (ln == NILLNODE) {
  89.     if (list->isCirc) {
  90.         nLNode->prevPtr = nLNode->nextPtr = nLNode;
  91.     } else {
  92.         nLNode->prevPtr = nLNode->nextPtr = NilListNode;
  93.     }
  94.     list->firstPtr = list->lastPtr = nLNode;
  95.     } else {
  96.     nLNode->prevPtr = lNode->prevPtr;
  97.     nLNode->nextPtr = lNode;
  98.     
  99.     if (nLNode->prevPtr != NilListNode) {
  100.         nLNode->prevPtr->nextPtr = nLNode;
  101.     }
  102.     lNode->prevPtr = nLNode;
  103.     
  104.     if (lNode == list->firstPtr) {
  105.         list->firstPtr = nLNode;
  106.     }
  107.     }
  108.     
  109.     return (SUCCESS);
  110. }
  111.     
  112. @
  113.